package cn.wolfcode.wms.web.controller;


import cn.wolfcode.wms.domain.Permission;
import cn.wolfcode.wms.query.QueryObject;
import cn.wolfcode.wms.service.IPermissionService;
import cn.wolfcode.wms.util.JSONResult;
import cn.wolfcode.wms.util.NeedPermission;
import cn.wolfcode.wms.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    @NeedPermission("权限列表")
    @RequestMapping("list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model){
        PageResult pageResult = permissionService.queryResult(qo);
        model.addAttribute("result",pageResult);

        return "permission/list";
    }

    //加载权限
    @NeedPermission("权限加载")
    @RequestMapping("reload")
    @ResponseBody
    public Object reload(){

        permissionService.loadRole();

        return new JSONResult();
    }

    @RequestMapping("delete")
    public String delete(Long id){

        permissionService.delete(id);
        return "redirect:/permission/list.do";
    }

}
